package com.bdmc.web.controller.report;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bdmc.common.annotation.RepeatSubmit;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.domain.AjaxResult;
import com.bdmc.common.core.validate.AddGroup;
import com.bdmc.common.core.validate.EditGroup;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.report.domain.vo.ReportCarOilVo;
import com.bdmc.report.domain.bo.ReportCarOilBo;
import com.bdmc.report.service.IReportCarOilService;
import com.bdmc.common.core.page.TableDataInfo;


/**
 * 车辆油量统计控制器
 *
 * @author bdmc
 * @date 2022-08-10
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/report/carOil")
public class ReportCarOilController extends BaseController {

    private final IReportCarOilService iReportCarOilService;

    /**
     * 查询车辆油量统计列表
     */
    @SaCheckPermission("report:carOil:list")
    @GetMapping("/list")
    public TableDataInfo<ReportCarOilVo> list(@Validated(QueryGroup.class) ReportCarOilBo bo, PageQuery pageQuery) {
        return iReportCarOilService.mySelectPage(bo, pageQuery);
    }

    /**
     * 导出车辆油量统计列表
     */
    @SaCheckPermission("report:carOil:export")
    @Log(title = "车辆油量统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated ReportCarOilBo bo, HttpServletResponse response) {
        List<ReportCarOilVo> list = iReportCarOilService.queryList(bo);
        ExcelUtil.exportExcel(list, "车辆油量统计", ReportCarOilVo.class, response);
    }

    /**
     * 获取车辆油量统计详细信息
     */
    @SaCheckPermission("report:carOil:query")
    @GetMapping("/{oilId}")
    public AjaxResult<ReportCarOilVo> getInfo(@PathVariable("oilId") Long oilId) {
        return AjaxResult.success(iReportCarOilService.queryById(oilId));
    }

    /**
     * 新增车辆油量统计
     */
    @SaCheckPermission("report:carOil:add")
    @Log(title = "车辆油量统计", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ReportCarOilBo bo) {
        return toAjax(iReportCarOilService.insertByBo(bo));
    }

    /**
     * 修改车辆油量统计
     */
    @SaCheckPermission("report:carOil:edit")
    @Log(title = "车辆油量统计", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ReportCarOilBo bo) {
        return toAjax(iReportCarOilService.updateByBo(bo));
    }

    /**
     * 删除车辆油量统计
     */
    @SaCheckPermission("report:carOil:remove")
    @Log(title = "车辆油量统计" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{oilIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] oilIds) {
        return toAjax(iReportCarOilService.deleteWithValidByIds(Arrays.asList(oilIds), true));
    }
}
